package com.chezhujie.www.service;

import com.chezhujie.www.domain.Czjprovince;
import com.chezhujie.www.persistence.CzjprovinceMapper;
import com.xy.core.exception.ClassCheckException;
import com.xy.core.page.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 省份
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class CzjprovinceService {
    @Autowired
    private CzjprovinceMapper czjprovinceMapper;

    public Pagination list(int pageNo, int pageSize, Map<String, Object> params, ModelMap model) throws Exception {

        Pagination pagination = new Pagination();
        pagination.setPageNo(pageNo);
        pagination.setPageSize(pageSize);
        params.putAll(pagination.toMap());
        int count = czjprovinceMapper.getTotalRows(params);
        List<Map<String, Object>> list = czjprovinceMapper.getList(params);
        pagination.setTotalCount(count);
        pagination.setList(list);
        return pagination;
    }


    public void insert(Czjprovince czjprovince){
        czjprovinceMapper.insert(czjprovince);
    }

    public void update(Czjprovince czjprovince){
        czjprovinceMapper.update(czjprovince);
    }
    public void deleteById(String id){
        czjprovinceMapper.deleteById(id);
    }
    public void deleteByIds(List<String> list){
        czjprovinceMapper.deleteByIds(list);
    }
    public Czjprovince queryById(String id){
        return czjprovinceMapper.queryById(id);
    }
    public List<Czjprovince> queryByIds(List<String> list){
        List<Czjprovince> listCzjprovince = czjprovinceMapper.queryByIds(list);
        if(listCzjprovince==null){
            listCzjprovince = new ArrayList<Czjprovince>();
        }
        return listCzjprovince;
    }

    public void checkEntity(Czjprovince czjprovince) throws Exception {
            if(czjprovince.getProvince().length()<255){
                throw new ClassCheckException("省份省名不能超过255个字符");
            }


    }
}
